import { ObjectAbstractClass, PersonAbstractClass, SceneAbstractClass } from "../abstract/abstract";

export class Scene extends SceneAbstractClass {

    public Persons: PersonAbstractClass[] = [];
    public Objects: ObjectAbstractClass[] = [];

    public init(): void {
        console.log("场景开始")
        // 开启轮回器
        this.timer();

    }
    public setPerson(person: PersonAbstractClass): void {
        this.Persons.push(person)
    }
    public setObject(object: ObjectAbstractClass): void {
        this.Objects.push(object);
    }
    
    /**
     * 时间计数器
     */
    public timer (){

        // 获取所有物体计数器
        const object = this.Objects;

        object.forEach((e)=> {
            // 跳动进度条
            e.addTimerLine();
        })

        const isTimerStart = object.filter((e)=> {
            // 跳动进度条
            return e.isTimerStart()
        })
        
        // 是否存在已经满足时间轴的对象
        if( isTimerStart.length > 0 ){
            isTimerStart.startTime();
        }

        return this.timer()

    }
}